<template>
	<div>
    <img class="user-poster" src="https://img.yzcdn.cn/public_files/2017/10/23/8690bb321356070e0b8c4404d087f8fd.png">
    <van-row class="user-links">
      <van-col span="6">
        <van-icon name="pending-payment" /> 待付款
      </van-col>
      <van-col span="6">
        <van-icon name="pending-orders" /> 待接单
      </van-col>
      <van-col span="6">
        <van-icon name="pending-deliver" /> 待发货
      </van-col>
      <van-col span="6">
        <van-icon name="logistics" /> 待发货
      </van-col>
    </van-row>

    <van-cell-group class="user-group">
      <van-cell icon="records" title="全部订单" is-link />
    </van-cell-group>

    <van-cell-group>
      <van-cell icon="exchange" title="我的积分" is-link />
      <van-cell icon="gold-coin" title="我的优惠券" is-link />
      <van-cell icon="gift" title="我收到的礼物" is-link />
    </van-cell-group>
  </div>
</template>
	
<script>	
  import {
    Row,
    Col,
    Icon,
    Cell,
    CellGroup
  } from "vant";
  import tips from "~/h5plus/Tips";
  import store from "~/h5plus/Storage";
  import cache from "~/Cache";
  import utils from "~/Utils";

//import ServiceCache from "api/globalCache";

  export default {
  	
    components: {
      [Row.name]: Row,
      [Col.name]: Col,
      [Icon.name]: Icon,
      [Cell.name]: Cell,
      [CellGroup.name]: CellGroup
    },
    data() {
      return {
        isLogin2: false,
        parkingRecordCount: 0,
        carCount: 0,
        userData: {
          nickName: '',
          phone: ''
        }
      }
    },
    async created() {
      this.getUser();

//    const res = await ServiceCache.Start();
//    const { carCount, parkingRecordCount } = res;
//    this.parkingRecordCount = parkingRecordCount;
//    this.carCount = carCount;
//    this.$apply();

    },
    computed: {
      user() {
        return ;this.userData;
      },
      loginState() {
        return this.isLogin2;
      }
    },
    mounted() {
      let self = this;
      window.addEventListener('pageflowrefresh', function (e) {
        //另一个界面触发此界面的事件
        console.log('我被刷新了')
        console.log(JSON.stringify(e))
        self.getUser();

      });
    },
    methods: {
      getUser() {
        console.log('user---')
        let result = cache.getUserInfo();
        let user = result.item || ''
        let self = this;
        console.log(user)

        if (user && user.userId) {
          this.isLogin2 = true;
          Object.assign(self.userData, user);
        }
      },
      openUserEdit() {
        if (this.isLogin()) {
          utils.openModal({
            url: "./mine.personal_edit.html",
            id: "mine.personal_edit",
            navbar: false
          });
        }

      },
      openMsg() {

        if (this.isLogin()) {
          utils.openModal({
            url: "./msg.msg_index.html",
            id: "msg.msg_index",
            navbar: false
          });
        }

      },
      openSetting() {
	      if(this.isLogin()) {
		          utils.openModal({
		            url: "./system.setting.html",
		            id: "system.setting",
		            navbar: false
		          });
	        }
//
      },
      openStopRecords() {
        // tips.alert('openStopRecords');
        if (this.isLogin()) {
          utils.openModal({
            url: "./mycar.stopCarRecord.html",
            id: "mycar.stopCarRecord",
            navbar: false
          });
        }
      },
      openMyOrders() {
        tips.alert("openMyOrders");
      },
      openMyPakeage() {

        if (this.isLogin()) {
          utils.openModal({
            url: "./wallet.index.html",
            id: "wallet.index",
            navbar: false
          });
        }

      },
      openSpread() {
        if (this.isLogin()) {
          utils.openModal({
            url: "./system.spread.html",
            id: "system.spread",
            navbar: false
          });
        }
      },
      openMyCar() {
        if (this.isLogin()) {
          utils.openModal({
            url: "./mycar.index.html",
            id: "mycar.index",
            navbar: false
          });
        }
      }
    }
  };
</script>
<style lang="less">
.user {
  &-poster {
    width: 100%;
    // height: 4rem;
    display: block;
  }
  &-group {
    margin-bottom: 0.3rem;
  }
  &-links {
    padding: 15px 0;
    font-size: 12px;
    text-align: center;
    background-color: #fff;
    .van-icon {
      display: block;
      font-size: 24px;
    }
  }
}
</style>
